#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int minCost(vector<vector<int>>& costs) {
        int n = costs.size();
        vector<int> red(n);
        auto blue = red;
        auto green = red;
        red[0] = costs[0][0];
        blue[0] = costs[0][1];
        green[0] = costs[0][2];
        for (int i = 1;i < n;i++)
        {
            red[i] = min(blue[i - 1], green[i - 1]) + costs[i][0];
            blue[i] = min(red[i - 1], green[i - 1]) + costs[i][1];
            green[i] = min(blue[i - 1], red[i - 1]) + costs[i][2];
        }
        return min(min(red[n - 1], blue[n - 1]), green[n - 1]);
    }
};